using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DrawContent : MonoBehaviour
{
    public Image image { get { return m_PaintBoard.image; } }
    public Ship m_Ship = null;
    public InputField m_NameEdit;
    public Dropdown m_LevelDropdown;
    public PaintBoard m_PaintBoard;
    public Text m_MassValue;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {

    }
    public void Init(Ship ship)
    {
        m_Ship = ship;
        m_NameEdit.text = m_Ship.m_TypeName;
        m_PaintBoard.imageSize = new Vector2Int((int)m_Ship.m_Level, (int)m_Ship.m_Level);
        m_PaintBoard.SetSprite(ship.GetComponent<SpriteRenderer>().sprite);
    }
    public void OnLevelChanged(int level)
    {
        Ship.Level shipLevel = Ship.Level.D;
        switch (level)
        {
            case 0:
                shipLevel = Ship.Level.D;
                break;
            case 1:
                shipLevel = Ship.Level.C;
                break;
            case 2:
                shipLevel = Ship.Level.B;
                break;
            case 3:
                shipLevel = Ship.Level.A;
                break;
            case 4:
                shipLevel = Ship.Level.AP;
                break;
        }

        m_Ship.m_Level = shipLevel;
        m_PaintBoard.imageSize = new Vector2Int((int)m_Ship.m_Level, (int)m_Ship.m_Level);
        m_PaintBoard.SetSprite(Sprite.Create(new Texture2D(m_PaintBoard.imageSize.x, m_PaintBoard.imageSize.y), new Rect(0, 0, m_PaintBoard.imageSize.x, m_PaintBoard.imageSize.y), new Vector2(0.5f, 0.5f)));
        m_PaintBoard.ClearUp();
        m_PaintBoard.Reset();
    }
    public void ApplyDataToShip()
    {
        var shipImage = m_PaintBoard.image;
        //m_Ship.SetImage(Sprite.Create(shipImage.sprite.texture, new Rect(0, 0, shipImage.sprite.texture.width, shipImage.sprite.texture.height), new Vector2(0.5f, 0.5f)));
        m_Ship.SetImage(shipImage.sprite);
    }
    public void OnNameEditFinished(string name)
    {
        m_Ship.m_TypeName = name;
    }

}
